import torch.utils.data as Data
model = CNNLSTM()
model.load_state_dict(torch.load("./state_dict_TemperModel.pt")) # 加载模型参数
model.eval()
# 将内部的training参数设置为FALSE, 在模型进行预测时,不再继续计算梯度值
test_x = torch.from_numpy(x_test)
test_y = torch.from_numpy(y_test)
test_dataset = Data.TensorDataset(test_x ,test_y)
test_loader= Data.DataLoader(test_dataset,batch_size=20,shuffle=False)
for step, (features, label) in enumerate(test_loader):
    predict = model(features) # predict:(None,1)    
    predict_y = predict.data.numpy()
    label_y =label.data.numpy()
    # 或
    # predict_y=scaler_y.inverse_transform(predict.data.numpy())
    #label_y=scaler_y.inverse_transform(label.data.numpy())
    #反归一化,获得归一化之前的标签值
    # 绘制对比曲线
    fig = plt.figure(figsize=(10, 10))  # 画板大小
    ax = fig.add_subplot(111)  # 画板上添加一张图
    # 绘制真实值曲线
    ax.plot(label_y, 'b-', label='actual')
    # 绘制预测值曲线
    ax.plot(predict_y, 'r--', label='predict')
    plt.legend()   
    plt.show()
    break  
